package com.wowangz.cms.common.utils;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * Description: 唯一标识符生成工具<br />
 * This program is protected by copyright iol-commons.<br />
 * Program Name: iol-commons<br />
 * Date: 2016年2月1日
 *
 * @author 王鑫
 * @version 1.0
 */
public class UUIDGenerator {
    /**
     * 获得订单编号 
     * @author jay.liu
     * @return 
     * String 
     * @date Dec 26, 2013 2:05:51 PM
     */
    public static synchronized String getNumId(){
        Random rad=new Random();
        StringBuffer str = new StringBuffer();
        str.append(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
        str.append(rad.nextInt(10000));
        str.append("");
        
        return str.toString();
    }
    
    /**
     * 获取UUID<br />
     * @return
     */
    public static String getUUID() {
    	String s = UUID.randomUUID().toString();
    	
    	return String.format("%s%s%s%s%s", s.substring(0,8), s.substring(9,13), s.substring(14,18), s.substring(19,23), s.substring(24));
    }
    
    /**
     * 获取UUID，去掉前缀的位数，保持32位不变<br />
     * @param prefix
     * @return
     */
    public static String getUUID(String prefix) {
    	int len = prefix.length();
    	
    	StringBuilder sb = new StringBuilder();
    	sb.append(prefix);
    	sb.append(getUUID().substring(len));
    	
    	return sb.toString();
    }
}